<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="/static/jQuery-3.3.1.js"></script>
    <title>ajax_file</title>
</head>
<body>

<p><input type="file" name="my_file" id="my_file"></p>
<button class="btn">提交</button>

</body>
<script>
    $(".btn").on("click", function () {
        var formdata = new FormData()
        formdata.append("my_file", $("#my_file")[0].files[0])
        $.ajax({
            url: "{% url 'ajax_file' %}",
            type: "post",
            processData: false,
            contentType: false,
            data: formdata,
            success: function (data) {
                console.log(data)
            }
        })
    })
</script>

</html>